package city.spring.modules.material.service.impl;

import city.spring.modules.material.entity.MaterialreceiptMaterialExtEntity;
import city.spring.modules.material.repository.MaterialreceiptMaterialExtRepository;
import city.spring.modules.material.service.MaterialreceiptMaterialExtService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service：物资领用与物资关系表
 *
 * @author 谢金婷
 * @date 2020-12-17 11:48:32
 */
@CacheConfig(cacheNames = {MaterialreceiptMaterialExtServiceImpl.CACHE_NAME})
@Transactional(rollbackFor = Exception.class)
@Service
public class MaterialreceiptMaterialExtServiceImpl extends ServiceImpl<MaterialreceiptMaterialExtRepository, MaterialreceiptMaterialExtEntity> implements MaterialreceiptMaterialExtService {

    private final MaterialreceiptMaterialExtRepository materialreceiptMaterialExtRepository;

    public MaterialreceiptMaterialExtServiceImpl(MaterialreceiptMaterialExtRepository materialreceiptMaterialExtRepository) {
        this.materialreceiptMaterialExtRepository = materialreceiptMaterialExtRepository;
    }

    @Override
    public void saveMaterialreceiptMaterialExt(MaterialreceiptMaterialExtEntity entity) {
        if (!save(entity)) {
            throw new RuntimeException("保存信息失败");
        }
    }

    @Override
    public void updateMaterialreceiptMaterialExt(MaterialreceiptMaterialExtEntity entity) {
        // 使用 updateById(entity); 修改数据时，将会修改 entity 对象中所有非null数据，如果某个字段为null，将会忽略该字段的修改
        if (!updateById(entity)) {
            throw new RuntimeException("修改信息失败");
        }
    }

    @Override
    public void deleteMaterialreceiptMaterialExt(String primaryKey) {
        removeById(primaryKey);
    }

    @Override
    public void deleteMaterialreceiptMaterialExt(List<String> primaryKeys) {
        removeByIds(primaryKeys);
    }

    @Override
    public List<MaterialreceiptMaterialExtEntity> getByMaterialreceiptId(String materialreceiptId) {
        return materialreceiptMaterialExtRepository.getByMaterialreceiptId(materialreceiptId);
    }
}